package com.test.until;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

public class UnSafeInstance {

    public static Unsafe reflectGetUnsafe(){
        try {
            //  Unsafe 魔法类，可直接绕过jvm虚拟机操作计算机底层，方法里面有大量native方法。只能通过反射获取
            Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
            theUnsafe.setAccessible(true);
            return (Unsafe) theUnsafe.get(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
